﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//请先添加引用
namespace TierApplication
{
	/// <summary>
	/// 类T_Region。
	/// </summary>
	public class T_Region
	{
		public T_Region()
		{}
		#region Model
		private string _regionid;
		private string _regionname;
		/// <summary>
		/// 
		/// </summary>
		public string RegionID
		{
			set{ _regionid=value;}
			get{return _regionid;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string RegionName
		{
			set{ _regionname=value;}
			get{return _regionname;}
		}
		#endregion Model


		#region  Method

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public T_Region(string RegionID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  ");
			strSql.Append("RegionID,RegionName ");
			strSql.Append(" from T_Region ");
			strSql.Append(" where RegionID='"+RegionID+"' ");
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				RegionID=ds.Tables[0].Rows[0]["RegionID"].ToString();
				RegionName=ds.Tables[0].Rows[0]["RegionName"].ToString();
			}
		}


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string RegionID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_Region where RegionID='"+RegionID+"' " );
			return DbHelperSQL.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into [T_Region](");
			strSql.Append("RegionID,RegionName");
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append("'"+RegionID+"',");
			strSql.Append("'"+RegionName+"'");
			strSql.Append(")");
			DbHelperSQL.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Region set ");
			strSql.Append("RegionName='"+RegionName+"'");
			strSql.Append(" where RegionID='"+RegionID+"' ");
			DbHelperSQL.ExecuteSql(strSql.ToString());
		}


		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string RegionID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_Region ");
			strSql.Append(" where RegionID='"+RegionID+"' ");
				DbHelperSQL.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public void GetModel(string sRegionID)
		{

			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" RegionID,RegionName ");
			strSql.Append(" from T_Region ");
            strSql.Append(" where RegionID='" + sRegionID + "' ");
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				RegionID=ds.Tables[0].Rows[0]["RegionID"].ToString();
				RegionName=ds.Tables[0].Rows[0]["RegionName"].ToString();
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM T_Region ");
			if(strWhere.Trim()!="")
			{

				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

        public static DataSet GetAllRegionList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM T_Region ");
            return DbHelperSQL.Query(strSql.ToString());
        }

		#endregion  Method
	}
}

